<?php


/***************************************************************/
/*** Local Functions                                          **/
/***************************************************************/

function echoPages($numMatches, $maxResults, $end, $prevIdx) {
	$prev = "&nbsp;";
	$endText = "&nbsp;";
	if ($end > $maxResults) {
		$prev = "<a href=\"./results.php?idx=" . $prevIdx . "\">Previous Results";
	}
	if ($end != $numMatches) {
		$endText = "<a href=\"./results.php?idx=" . $end . "\">More Results";
	}
	if ($numMatches > $maxResults) {
		echo<<< EOQ
      <tr>
        <td colspan="3" align="left">$prev</td>
        <td colspan="3" align="right">$endText</td>
      </tr>

EOQ;
	}
}

/***************************************************************/
/*** End Local Functions                                      **/
/***************************************************************/
include_once ("includes/init.php");
$title =$season->season . " results";
include_once ("includes/match_utils.php");
include_once ("includes/header.php");
$image = $season->getImage();
echo<<< EOQ
  <caption><h1>League Results<br />$season->season $image</h1></caption>
  
EOQ;
$submit = getParam("submit");
$mrid = getParam("mrid");
$comments = getParam("comments");
if (isset ($loggedin)) {
	echo "<tr><td colspan=\"6\" align=\"center\"><h3><a href=\"match_create.php\">Submit a result</a></h3>";
	if (isset ($submit) && $matches->updateMatchRecord($mrid, stripslashes($comments))) {
		echo "<br /><font color=white>Comment updated</font>";
	}
	echo "</td></tr>";
}

$idx = getParam("idx");
if (!isset ($idx)) {
	$idx = 0;
}
$maxResults = 10;
$rowcount = 0;
$prevIdx = $idx > $maxResults ? $idx - $maxResults : 0;
$end = $idx + $maxResults > $matches->numMatches() ? $matches->numMatches() : $idx + $maxResults;

echoPages($matches->numMatches(), $maxResults, $end, $prevIdx);

showMatchResultHeader();
for (; $idx < $end; $idx++) {
	$match = $matches->matches[$idx];
	showMatchResult($match, $rowcount);
}

echoPages($matches->numMatches(), $maxResults, $end, $prevIdx);

include ("includes/footer.php");
?>
